home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / viewkit / xcontact / lib / OkTArray.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.3 KB  |  80 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. ///////////////////////////////////////////////////////////////////////////
  18. // OkTArray.c++
  19. ///////////////////////////////////////////////////////////////////////////
  20. #include "OkTArray.h"
  21. #include <iostream.h>
  22.  
  23.  
  24. template <class Type> void 
  25. OkTArray<Type>::createElements(void * start, u_int numbytes) 
  26. {
  27.     Type *ptr = (Type *) start;
  28.     while(numbytes) {
  29.         numbytes -= elementsize;
  30.         Type * obj = new(ptr) Type;                    
  31.         ptr++;                             
  32.     }                                
  33. }                                    
  34.  
  35.  
  36. template <class Type> void 
  37. OkTArray<Type>::destroyElements(void * start, u_int numbytes) 
  38. {        
  39.     Type * ptr = (Type *)start;                    
  40.     while (numbytes) {
  41.         numbytes-=elementsize;
  42. // Working with Shankar Uni now....
  43. // This turns out to be cfront 3.0 bug.
  44. //        ptr->Type::~Type();                        
  45. //        cerr <<"ptr->destroy()\n";
  46.         ptr->destroy();// Kludge to work around.  Element must have
  47.                 // void destroy() { this->~Type(); }
  48.         ptr++;                            
  49.     }                                
  50. }                                    
  51.  
  52.  
  53. template <class Type> void 
  54. OkTArray<Type>::copyElements(void * src, void * dst, u_int numbytes) 
  55. {                    
  56.     if (src<dst) {                            
  57.         src = (char*)src + numbytes;                
  58.         dst = (char*)dst + numbytes;                
  59.         Type * p = (Type*)src - 1;            
  60.         Type * q = (Type*)dst - 1;                    
  61.         while (numbytes > 0) {                    
  62. //        Type * obj = new(q--) Type(*p--);    
  63.         Type * obj = new(q--) Type;
  64.         *obj = *p--;
  65.         numbytes -= elementsize;                
  66.         }                                
  67.     } else {                            
  68.         Type * p = (Type*)src;                
  69.         Type * q = (Type*)dst;                    
  70.         while (numbytes > 0) {                    
  71. //        Type * obj = new(q++) Type(*p++);            
  72.         Type * obj = new(q++) Type;
  73.         *obj = *p++;
  74.         numbytes -= elementsize;                
  75.         }                                
  76.     }                                
  77. }                                    
  78.  
  79.  
  80.